clear all
set more off
set mem 100m
tempfile temp

/* 

This dofile categorizes variables on participation into civil associations. The raw dara comes from module on citizen's participation (participacion ciudadana, modulo 84)


*/

local data ../../../../../data/enaho
local working ../working

forvalues y = 2004/2016 {
	use `data'/`y'/enaho01-`y'-800b, clear
	di as error "`y'"
	label list p803
	drop if p803 > 12
	gen partN = 1 
	recode p803 (1 = 1) (2/12 = 0), gen(part_sport)
	recode p803 (2 = 1) (1 3/12 = 0), gen(part_party)
	recode p803 (3 = 1) (1/2 4/12 = 0), gen(part_cultu)
	recode p803 (4 = 1) (1/3 5/12 = 0), gen(part_neigh)
	recode p803 (5 = 1) (1/4 6/12 = 0), gen(part_ronda)
	recode p803 (6 = 1) (1/5 7/12 = 0), gen(part_water)
	recode p803 (7 = 1) (1/6 8/12 = 0), gen(part_proff)
	recode p803 (8 = 1) (1/7 9/12 = 0), gen(part_union)
	recode p803 (9 = 1) (1/8 10/12 = 0), gen(part_mothe)
	recode p803 (10 = 1) (1/9 11/12 = 0), gen(part_apafa)
	recode p803 (11 = 1) (1/10 12 = 0), gen(part_milk)
	recode p803 (12 = 1) (1/11 = 0), gen(part_food)
	
	collapse (sum) part*, by(conglome vivienda hogar codperso)
	destring conglome vivienda hogar codperso, replace
	keep conglome vivienda hogar codperso part*
	gen year = `y'
	
	compress
	save part_`y', replace
}

use part_2004
forvalues y = 2005/2016 {
	append using part_`y'
}	

forvalues y = 2004/2016 {
	erase part_`y'.dta
}	

compress
save `working'/participation, replace
